package com.leyou.common.threadlocals;

import com.leyou.common.auth.entity.UserInfo;

/**
 * 容器，用于存储用户数据
 *
 * @author chao
 */
public class UserHolder {
    public static final ThreadLocal<UserInfo> THREAD_LOCAL = new ThreadLocal<>();

    /**
     * 设置用户数据
     *
     * @param user
     */
    public static void setUser(UserInfo user) {
        THREAD_LOCAL.set(user);
    }

    /**
     * 获取用户数据
     *
     * @return 用户数据
     */
    public static UserInfo getUser() {
        return THREAD_LOCAL.get();
    }

    /**
     * 删除用户数据
     */
    public static void removeUser() {
        THREAD_LOCAL.remove();
    }
}
